package com.ssy.lingxi.member.merchant.utils;

import com.ssy.lingxi.member.merchant.model.bo.FileBO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.FileUploadVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.FileVO;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * FileBO, FileVO, FileUpload工具类
 * @author yzc
 * @version 2.0.0
 * @date 2021/6/7
 */
public class FileObjectUtil {

    /**
     * 将FileUpload转换为FileBO
     * @param obj FileUploadVO对象
     * @return 转换结果
     */
    public static FileBO toBO(FileUploadVO obj) {
        return new FileBO(obj.getName(), obj.getUrl());
    }

    /**
     * 将集合FileUploadVO转换为FileBO集合
     * @param objs FileUploadVO集合
     * @return 转换结果
     */
    public static List<FileBO> toBOList(Collection<FileUploadVO> objs) {
        if (CollectionUtils.isEmpty(objs)) {
            return Collections.emptyList();
        }
        return objs.stream().map(fileBO -> new FileBO(fileBO.getName(), fileBO.getUrl())).collect(Collectors.toList());
    }

    /**
     * 将FileBO转换为FileVO
     * @param obj FileBO对象
     * @return 转换结果
     */
    public static FileVO toVO(FileBO obj) {
        return new FileVO(obj.getName(), obj.getUrl());
    }

    /**
     * 将集合FileBO转换为FileVO集合
     * @param objs FileBO集合
     * @return 转换结果
     */
    public static List<FileVO> toVOList(Collection<FileBO> objs) {
        if (CollectionUtils.isEmpty(objs)) {
            return Collections.emptyList();
        }
        return objs.stream().map(fileBO -> new FileVO(fileBO.getName(), fileBO.getUrl())).collect(Collectors.toList());
    }
}
